package com.hxy.tlias.controller;


import com.hxy.tlias.annotation.Log;
import com.hxy.tlias.pojo.Emp;
import com.hxy.tlias.pojo.EmpQueryParam;
import com.hxy.tlias.pojo.PageBean;
import com.hxy.tlias.pojo.Result;
import com.hxy.tlias.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@Slf4j
@RequestMapping("/emps")
@RestController
public class EmpController {
    @Autowired
    private EmpService empService;

    /**
     * 列表查询（条件分页查询）
     * @return
     */
    @GetMapping
    public Result page(EmpQueryParam param){
        log.info("分页查询，{},{},{},{},{},{}",param.getName(),param.getGender(),param.getBegin(),param.getEnd(),param.getPage(),param.getPageSize());
        PageBean pageBean = empService.page(param);
        return Result.success(pageBean);
    }

    /**
     * 新增员工
     * @param emp
     * @return
     */
    @Log
    @PostMapping
    public Result save(@RequestBody Emp emp){
        log.info("新增员工，{}",emp);
        empService.save(emp);
        return Result.success();
    }

    /**
     * 删除员工
     * @param ids
     * @return
     */
    @Log
    @DeleteMapping
    public Result delete(@RequestParam List<Integer> ids){
        log.info("删除员工，{}",ids);
        empService.delete(ids);
        return Result.success();
    }

    /**
     * 修改员工-回显
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        log.info("回显员工，id={}",id);
        Emp emp =empService.getById(id);
        return Result.success(emp);
    }
    @Log
    @PutMapping
    public Result update(@RequestBody Emp emp){
        log.info("修改员工，emp={}",emp);
        empService.update(emp);
        return Result.success();
    }

}
